/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.eng.scc.core.schema.fetcher;

import com.eng.scc.core.data.Filling;
import com.eng.scc.core.db.Database;
import com.eng.scc.core.db.Fetcher;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Rafael
 */
public class FillingFetcher implements Fetcher<Filling>
{
    @Override
    public Filling fetch( ResultSet ps ) throws Exception
    {
        Filling f = new Filling();
        
        f.setId( ps.getInt( 1 ) );
        f.setFreightId( ps.getInt( 2 ) );
        f.setQuantity( ps.getDouble( 3 ) );
        f.setKm( ps.getString( 4 ) );
        f.setLocale( ps.getString( 5 ) );
        f.setDate( ps.getDate( 6 ) );
        f.setAvg( ps.getDouble( 7 ) );
        f.setLiterPrice( ps.getDouble( 8 ) );
        
        return f;
    }

    @Override
    public void insert( Filling value, PreparedStatement ps ) throws Exception
    {
        value.setId( Database.getInstance().nextID( "core_fillings" ) );
        
        ps.setInt( 1, value.getId() );
        ps.setInt( 2, value.getFreightId() );
        ps.setDouble( 3, value.getQuantity() );
        ps.setString( 4, value.getKm() );
        ps.setString( 5, value.getLocale() );
        ps.setDate( 6, value.getDate() );
        ps.setDouble( 7, value.getAvg() );
        ps.setDouble( 8, value.getLiterPrice() );

    }

    @Override
    public void update( Filling value, PreparedStatement ps ) throws Exception
    {
        ps.setInt( 1, value.getFreightId() );
        ps.setDouble( 2, value.getQuantity() );
        ps.setString( 3, value.getKm() );
        ps.setString( 4, value.getLocale() );
        ps.setDate( 5, value.getDate() );
        ps.setDouble( 6, value.getAvg() );
        ps.setDouble( 7, value.getLiterPrice() );
        ps.setInt( 7, value.getId() );
    }
    
}
